草庐IT

Spring 的覆盖 bean

全部标签

java - Intellij spring boot 扩展 gradle 构建文件中的 processResources 以替换属性

当使用gradlebuild命令从命令行构建时,属性字段被正确替换,但是,当使用IntelliJIDEAIDE时,它不是。代码在build.gradleext{port=8086}processResources{filesMatching('application.properties'){expand(project.properties)}}代码在application.propertiesserver.port=${port} 最佳答案 当您通过单击“运行”按钮在IntelliJ中运行SpringBoot应用程序时,它会以常

java - 带有 Eureka 服务器的 Spring Boot 1.4.2.RELEASE - 异常 : org. springframework.beans.factory.NoSuchBeanDefinitionException

尝试使用Eureka服务器运行SpringBoot1.4.2.RELEASE时出现以下错误:2016-11-2016:25:59.306INFO14263---[main]s.c.a.AnnotationConfigApplicationContext:Refreshingorg.springframework.context.annotation.AnnotationConfigApplicationContext@2177849e:startupdate[SunNov2016:25:59CET2016];rootofcontexthierarchy2016-11-2016:25:5

java - 如何将 JAXB 注释与 Spring RestTemplate 一起使用?

我正在尝试使用Spring的RestTemplate自动反序列化XML格式的响应。我正在使用Jackson的jackson-dataformat-xml模块,为此SpringBoot设置为自动配置。我想在要反序列化到的类中使用JAXB注释,但它似乎不起作用。这是我希望类看起来像的示例:@XmlRootElement(name="Book")publicclassBook{@XmlElement(name="Title")privateStringtitle;@XmlElement(name="Author")privateStringauthor;}这基于以下XML示例:MyBookM

java - Spring AMQP (Rabbit) 监听器在异常情况下进入循环

@BeanRabbitTemplaterabbitTemplate(){RabbitTemplatetemplate=newRabbitTemplate(rabbitConnectionFactory());template.setMessageConverter(messageConverter);template.setExchange(amqpProperties.getRabbitMqTopicExchangeName());returntemplate;}@Bean@Conditional(OperationsCondition.class)SimpleMessageList

java - 带有复合主键的 Spring 数据

我将springdatarest用于crud。但是当实体有复合主键时,我不知道如何通过提供主键来获取实体。河流类:@EntitypublicclassRiver{privateRiverPKid;privateDoublelength;privateTimestampdate;privateStringcomment;@Basic@Column(name="length")publicDoublegetLength(){returnlength;}publicvoidsetLength(Doublelength){this.length=length;}@Basic@Column(na

java - 是否可以在 Spring Data JPA 中将 @Lock 与 @Modifying @Query 与 Hibernate 结合使用?

在将@Lock注释与@Modifying@Query一起使用以及查询本身执行更新语句时,我遇到了问题。我的测试设置如下所示:SpringBootStarter1.5.3.RELEASEhibernate5.2.10.FinalSpringDataJPA1.11.3.RELEASE测试的数据库:H2、PostgreSQL、MariaDB、Oracle示例实体:importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persistence.Id;importjavax.persistence.Tab

Java Spring Boot - 使用有效载荷记录响应

我目前正在使用SpringBoot将请求/响应日志记录集成到REST服务中。对于请求,我选择了Spring提供的CommonsRequestLoggingFilter:@BeanpublicCommonsRequestLoggingFilterrequestLoggingFilter(){CommonsRequestLoggingFilterloggingFilter=newCommonsRequestLoggingFilter();loggingFilter.setIncludeClientInfo(false);loggingFilter.setIncludeQueryString

java - Spring MVC 忽略给定 Controller 方法的 Json 属性

我有一个Java类(MyResponse),它由多个RestController方法返回并且有很多字段。@RequestMapping(value="offering",method=RequestMethod.POST)publicResponseEntitypostOffering(...){}@RequestMapping(value="someOtherMethod",method=RequestMethod.POST)publicResponseEntitysomeOtherMethod(...){}我只想忽略(例如,不序列化它)一种方法的其中一个属性。我不想忽略该类的空字段

java - Spring Boot 仅在单元测试中返回错误的状态码

我正在使用SpringBoot开发RESTAPI。我有一个Controller来创建一个新用户,它在创建用户时以201(CREATED)响应。响应没有正文内容。使用Postman或任何浏览器,我收到了201响应。但是当我尝试使用单元测试(Mockito)时,响应是200。这是我的代码:Controller:publicCompletableFuture>registerNewUser(@RequestBody@ValidRegisterUserDtonewUser)throwsExecutionException,InterruptedException{//userservicere

java - 如何按名称模式从 IntelliJ 代码覆盖范围中排除文件?

我正在使用IntelliJ2017.3来衡量我的测试的代码覆盖率。代码库包含一些或多或少应该从该测量中排除的哑类。我想排除所有名称中包含Factory的类(例如:AverageOperatorFactoy),并尝试使用*Factory和.*Factory(虽然这里似乎没有使用正则表达式),但IntelliJ仍然在覆盖率报告中显示工厂。如何排除具有名称模式的类? 最佳答案 我在使用非常基本的模式时遇到了同样的问题,例如com.example.myproject.somecode.*虽然按预期包含作品,但排除根本没有效果。这似乎是Int